﻿using MtApi;
using MTEA.LIB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MTEA.UI
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            List<Tuple<string, int>> list = new List<Tuple<string, int>>();
            list.Add(new Tuple<string, int>("Main", 0));
            list.Add(new Tuple<string, int>("Upper", 1));
            list.Add(new Tuple<string, int>("Lower", 2));
            timeFramesComboBox.ItemsSource = System.Enum.GetNames(typeof(ENUM_TIMEFRAMES));
            OrderTypeComboBox.ItemsSource = System.Enum.GetNames(typeof(OrderType));
            BollingTypeComboBox.ItemsSource = list;

            timeFramesComboBox.SelectedIndex = 0;
            OrderTypeComboBox.SelectedIndex = 0;
            BollingTypeComboBox.SelectedIndex = 0;
        }

        private void confirmBtn_Click(object sender, RoutedEventArgs e)
        {
            int timeFrames = (int)System.Enum.Parse(typeof(ENUM_TIMEFRAMES), timeFramesComboBox.SelectedItem.ToString());
            double lots = double.Parse(lotsTxt.Text);
            int orderType=(int)System.Enum.Parse(typeof(OrderType), OrderTypeComboBox.SelectedItem.ToString());
            double duration = double.Parse(durationTxt.Text);
            var item = BollingTypeComboBox.SelectedItem as Tuple<string, int>;
            int bollingType = item.Item2;
            string result = string.Empty;
            if(orderType == (int)OrderType.Close)
            {
                result = string.Format("closeorder {0} {1} {2} {3}", timeFrames, lots, duration, bollingType);
            }
            else
            {
                result = string.Format("addtask {0} {1} {2} {3} {4}", timeFrames, lots, orderType, duration, bollingType);
            }
            resultTxtBlock.Text = result;
            Clipboard.SetDataObject(result);
        }
    }
}
